Fix Socket#reuse_port? if SO_REUSEPORT is not supported#6706
Fix Socket#reuse_port? if SO_REUSEPORT is not supported#6706RX14 merged 2 commits intocrystal-lang:masterfrom
Conversation
src/socket.cr
Outdated
|
|
||
| def reuse_port? | ||
| getsockopt_bool LibC::SO_REUSEPORT | ||
| 0 != getsockopt(LibC::SO_REUSEPORT, 0) do |errno| |
There was a problem hiding this comment.
Ouch, that looks sooo weird... Please, assign the return value to a variable and compare with that:
ret = getsockopt(LibC::SO_REUSEPORT, 0) do |errno|
# ...
end
ret != 0|
I'm not sure. |
|
My thinking is: If
I prefer either both or only the setter should raise. |
|
My thinking is "can I check So yeah, maybe the check should just return false, but trying to set the value must raise if unsupported. |
|
I've done some research and from what I've read, it seams that But, at least on WSL, |
|
There are however reports about |
|
Let Microsoft seal with WSL bugs. |
| def reuse_port? | ||
| getsockopt_bool LibC::SO_REUSEPORT | ||
| ret = getsockopt(LibC::SO_REUSEPORT, 0) do |errno| | ||
| # If SO_REUSEPORT is not supported, the return value should be `false` |
There was a problem hiding this comment.
no need for the comment: code is explicit enough.
The point is, it doesn't fail on WSL :( |
|
|
Yeah, sure. That's why I posted a comment in the WSL issue. It's just that Crystal's |
…#6706) * Fix Socket#reuse_port? if SO_REUSEPORT is not supported * fixup! Fix Socket#reuse_port? if SO_REUSEPORT is not supported
Currently, if
SO_REUSEPORTis not supported,LibC.getsockoptreturns-1. When callingSocket#reuse_port?this causes an exception.This PR fixes that to return
falseif errno isENOPROTOOPT(meaning thatSO_REUSEPORTis not supported).